export default{
	namespaced:true,
	state:{
		authToken:uni.getStorageSync('auth_token')||'',
		userInfo:JSON.parse(uni.getStorageSync("userInfo")||'{}'),
		// #ifdef MP-WEIXIN
		userInfoWx:JSON.parse(uni.getStorageSync("userInfoWx")||'{}'),
		tokenWx:uni.getStorageSync("tokenWx")||''
		// #endif
	},
	mutations:{
		SETAUTHTOKEN(state,payload){
			state.authToken=payload
			uni.setStorageSync('auth_token',payload)
		},
		SETUSERINFO(state,payload){
			state.userInfo=payload
			uni.setStorageSync("userInfo",JSON.stringify(payload))
		},
		REMOVEUSERINFO(state,payload){
			uni.removeStorageSync('auth_token')
			uni.removeStorageSync('userInfo')
			state.authToken=''
			state.userInfo={}
		},
		setUserInfoWx(state,payload){
			state.userInfoWx=payload
			uni.setStorageSync("userInfoWx",JSON.stringify(payload))
		},
		setTokenWx(state,payload){
			state.tokenWx=payload
			uni.setStorageSync("tokenWx",payload)
		}
		
	},
	actions:{
		async safeOutAsync(cxt,payload){
			console.log('------actions--safeOutAsync----------');
			const result=await uni.$api.mine.logoutApi(payload)
			if(result.data.status==1){
				cxt.commit('REMOVEUSERINFO')
			}
		},
		async getUserInfoAsync(cxt,payload){
			console.log('------actions--getUserInfoAsync----------');
			const result=await uni.$api.mine.getUserInfoApi(payload)
			cxt.commit('SETUSERINFO',result.data.data)
			if(result.data.status==1){
				uni.switchTab({
					url:'/pages/mine/mine'
				})
			}
			
		},
		async loginAsync(cxt,payload){
			console.log('------actions--loginAsync----------');
			const result=await uni.$api.mine.loginApi(payload)
			if(result.data.data){
				cxt.commit('SETAUTHTOKEN',result.data.data.auth_token)
				cxt.dispatch("getUserInfoAsync",result.data.data.uid)
			}
		}
	}
}